package blackitheima2.Desk;

public class Foodie extends Thread {
    private Desk desk;
    public Foodie(Desk desk) {
        this.desk=desk;
    }

    @Override
    public void run() {
       while(true){
           synchronized (desk.getLock()) {
               if (desk.getCount() == 0) {
                   break;
               } else {
                   if (desk.isFlag()) {
                       System.out.println("洒家来吃酒!");
                       desk.setFlag(false);
                       desk.getLock().notifyAll();
                       desk.setCount(desk.getCount() - 1);
                   } else {
                       try {
                           desk.getLock().wait();
                       } catch (InterruptedException e) {
                           e.printStackTrace();
                       }
                   }
               }
           }
       }
    }
}
